var jsDir = '/home/js/';
Ext.Loader.setPath('TinyCore', jsDir + 'ui');
Ext.Loader.setPath('Ext.ux', jsDir + 'ext/ux');
Ext.require([
	'Ext.ux.form.SearchField'
]);

// create default exception reload
Ext.override(Ext.data.Store, {
	listeners:{
		'loadexception': function(proxy, options, response){ 
			Ext.MessageBox.show({
				title: '异常',
				msg: Ext.decode(response.responseText).msg,
				buttons: Ext.Msg.OK,
				closable:false,
				icon: Ext.MessageBox.ERROR
			});		 
	 	}
	}
});

// TODO: ExtJS4.2.1 has bug that "allowBlank:false" field will make rowediting plugin update button disabled
//  override it to solve this. 
Ext.override(Ext.grid.RowEditor,{

  addFieldsForColumn: function(column, initial) {
    var me = this,
        i,
        length, field;


    if (Ext.isArray(column)) {
        for (i = 0, length = column.length; i < length; i++) {
            me.addFieldsForColumn(column[i], initial);
        }
        return;
    }


    if (column.getEditor) {


      field = column.getEditor(null, {
          xtype: 'displayfield',
          getModelData: function() {
              return null;
          }
      });
      if (column.align === 'right') {
          field.fieldStyle = 'text-align:right';
      }


      if (column.xtype === 'actioncolumn') {
          field.fieldCls += ' ' + Ext.baseCSSPrefix + 'form-action-col-field';
      }


      if (me.isVisible() && me.context) {
          if (field.is('displayfield')) {
              me.renderColumnData(field, me.context.record, column);
          } else {
              field.suspendEvents();
              field.setValue(me.context.record.get(column.dataIndex));
              field.resumeEvents();
          }
      }
      if (column.hidden) {
          me.onColumnHide(column);
      } else if (column.rendered && !initial) {
          me.onColumnShow(column);
      }
      
      // -- start edit
      me.mon(field, 'change', me.onFieldChange, me);
      // -- end edit
    }
  }
});
